﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using LIM.forms.uc_DanhMuc_ChiTieu;
using LIM.controller;
using LIM.model;
using Telerik.WinControls.UI;

namespace LIM.forms
{
    public partial class radForm_DanhMuc_ChiTieu : Telerik.WinControls.UI.RadForm
    {
        public DanhMucChiTieuController controller = new DanhMucChiTieuController();
        public radForm_DanhMuc_ChiTieu()
        {
            InitializeComponent();
        }
        public delegate void GridViewDoubleClick();
        public event GridViewDoubleClick OnRowChange;


        public tbl_DanhMuc_ChiTieu SelectedEntity { set; get; }
        public SYSController _SYSController = new SYSController();

        private void radForm_DanhMuc_ChiTieu_Load(object sender, EventArgs e)
        {
            loaddata();
            uc_DanhMuc_ChiTieu_ThongTinChiTieu uc_DanhMuc_ChiTieu_ThongTinChiTieu = new uc_DanhMuc_ChiTieu_ThongTinChiTieu();
            uc_DanhMuc_ChiTieu_ThongTinChiTieu.Dock = DockStyle.Fill;
            this.radPageViewPage_ThongTinChiTieu.Controls.Add(uc_DanhMuc_ChiTieu_ThongTinChiTieu);

            uc_DanhMuc_ChiTieu_BangGia uc_DanhMuc_ChiTieu_BangGia = new uc_DanhMuc_ChiTieu_BangGia();
            uc_DanhMuc_ChiTieu_BangGia.Dock = DockStyle.Fill;
            this.radPageViewPage_BangGia.Controls.Add(uc_DanhMuc_ChiTieu_BangGia);

            uc_DanhMuc_ChiTieu_PhuongPhap uc_DanhMuc_ChiTieu_PhuongPhap = new uc_DanhMuc_ChiTieu_PhuongPhap();
            uc_DanhMuc_ChiTieu_PhuongPhap.Dock = DockStyle.Fill;
            this.radPageViewPage_PhuongPhapThucHienKiemNghiem.Controls.Add(uc_DanhMuc_ChiTieu_PhuongPhap);

            uc_DanhMuc_ChiTieu_SuDungTaiSan uc_DanhMuc_ChiTieu_SuDungTaiSan = new uc_DanhMuc_ChiTieu_SuDungTaiSan();
            uc_DanhMuc_ChiTieu_SuDungTaiSan.Dock = DockStyle.Fill;
            this.radPageViewPage_SuDungTaiSan.Controls.Add(uc_DanhMuc_ChiTieu_SuDungTaiSan);

            uc_DanhMuc_ChiTieu_NhanVienThucHien uc_DanhMuc_ChiTieu_NhanVienThucHien = new uc_DanhMuc_ChiTieu_NhanVienThucHien();
            uc_DanhMuc_ChiTieu_NhanVienThucHien.Dock = DockStyle.Fill;
            this.radPageViewPage_NhanVienThucHien.Controls.Add(uc_DanhMuc_ChiTieu_NhanVienThucHien);

        }
        void loaddata()
        {
            radGridView3.DataSource = controller.Load();
            radGridView3.ClearSelection();    
        }

        private void radGridView3_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (IsClickedOnRowContent((RadGridView)sender, e.Location))
            {
                SelectedEntity = (tbl_DanhMuc_ChiTieu)this.radGridView3.CurrentRow.DataBoundItem;
                if (OnRowChange != null)
                    OnRowChange();
            }
        }
        /// <summary>
        /// Detect click on rows
        /// </summary>
        /// <param name="radGridView"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        private bool IsClickedOnRowContent(RadGridView radGridView, Point location)
        {
            int excludeHeight = 0;
            if (radGridView.ShowFilteringRow)
                excludeHeight += radGridView.TableElement.FilterRowHeight;
            if (radGridView.ShowGroupPanel)
                excludeHeight += radGridView.TableElement.GroupHeaderHeight;
            if (radGridView.ShowColumnHeaders)
                excludeHeight += radGridView.TableElement.TableHeaderHeight;
            if (excludeHeight < location.Y)
            {
                return true;
            }

            return false;
        }
        public void RefreshData()
        {
            radForm_DanhMuc_ChiTieu_Load(new object(), new EventArgs());
        }

        private void radMenuItem_Refresh_Click(object sender, EventArgs e)
        {
            RefreshData();
        }

        private void radMenuItem_TaoMoi_Click(object sender, EventArgs e)
        {
            radGridView3.ClearSelection();
            SelectedEntity = new tbl_DanhMuc_ChiTieu();
            if (OnRowChange != null)
                OnRowChange();
        }
    }
}
